package com.sailors.common.task.provider.infra.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sailors.common.task.provider.faced.model.enums.StatusEnum;
import com.sailors.common.task.provider.faced.model.vo.TaskProLogVo;
import com.sailors.common.task.provider.infra.repository.ITaskProLogRepository;
import com.sailors.common.task.provider.infra.repository.convert.TaskProConver;
import com.sailors.common.task.provider.infra.repository.dao.TaskProLogMapper;
import com.sailors.common.task.provider.infra.repository.model.FileTaskLogPo;
import com.sailors.common.task.provider.infra.repository.model.TaskProLogPo;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 任务表 服务实现类
 * </p>
 *
 * @author cyj
 * @since 2022-11-22
 */
@Service
public class TaskProLogRepository extends ServiceImpl<TaskProLogMapper, TaskProLogPo> implements ITaskProLogRepository {

    @Override
    public List<TaskProLogVo> getByTaskIds(List<Long> taskIds) {
        LambdaQueryWrapper<TaskProLogPo> wrapper = getWrapper();
        wrapper.in(TaskProLogPo::getTaskId, taskIds);
        wrapper.orderByDesc(TaskProLogPo::getId, TaskProLogPo::getProcess);
        List<TaskProLogPo> list = this.list(wrapper);
        return TaskProConver.INSTANCE.pos2Vos(list);
    }

    @Override
    public void save(Long taskId, BigDecimal process, String createBy) {
        this.save(new TaskProLogPo(taskId, process, createBy));
    }

    private LambdaQueryWrapper<TaskProLogPo> getWrapper() {
        return Wrappers.lambdaQuery();
    }
}
